﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Model.Admin;
using Model.WXshopBuiness;
using Services.WXProjectAdmin;
using Xproject.Util;

namespace WeiXinpProAdmin.Controllers
{
    public class AdminBaseController : CommonBaseController
    {
        //SystemMenuServices m_SystemMenuServices;

        //public AdminBaseController(SystemMenuServices mSystemMenuServices)
        //{
        //    m_SystemMenuServices = mSystemMenuServices;
        //}

        public AdminUser CurrentUser {
            get
            {
               
                if (this.GetSession() != null)
                {
                    AdminUser u  = this.GetSession() as AdminUser;
                    return u;
                }
                return null;
            }
        }

        public List<AdminMenu> CurrentUserMenus {
            get {
                if (CurrentUser != null) {
                    var obj = System.Web.HttpRuntime.Cache["CACHE_USER_MENU_" + CurrentUser.ID];
                    List<AdminMenu> temp = new List<AdminMenu>();
                    if (obj != null)
                    {
                        temp = obj as List<AdminMenu>;
                    }
                    return temp;
                }
                return null;
            }
        }


       

        protected override void OnActionExecuting(ActionExecutingContext filterContext)
        {            
            GoToLogin();
            base.OnActionExecuting(filterContext);
        }


        private void GoToLogin()
        {
            if (CommonHelper.GetAppSettings("DESIGN_DEBUGGER")=="0") {
                if (this.CurrentUser == null)
                {
                    string url = Request.RawUrl;
                    Response.Redirect("~/Login/Login?gotoUrl=" + url);
                }
            }
            
            
        }
    }
}